
//获取input值
let form = $("form");
let username = $("#username");
let password = $("#password");
var search = location.search

//表单验证
$("form").validate({
    rules: {
        username: {
            required: true,
            rangelength: [2, 5],
        },
        password: "required",
    },
    messages: {
        username: {
            required: "用户名是必填",
            rangelength: "用户名的长度必须在2-5之间",
        },
        password: "密码是必填",
    },
    submitHandler: async function () {
        let e = window.event;
        e.preventDefault();

        var txt=await PromiseAjax({
            url:"./login.php",
            data:`name='${username.val()}'&pass=${password.val()}`
        })
        // 判断php响应结果是否等于1
        if(txt==1){
            setCookie("name",username.val());
            if(search){
                alert("登录成功")
                var url=search.split('url=')[1]
                location=url;
            }else{
                alert("登录成功")
                location='../01index/index.html'
            }
        }else{
            alert("账号或密码错误")
            location.reload()
        }
    },
});

